package com.htdata.iiot;

import org.apache.commons.cli.BasicParser;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.HelpFormatter;
import org.apache.commons.cli.Options;


public class Cmd {
	
	public static String zk = null;
	public static String topic=null;
	public static String stattopic=null;
	public static String tenantIds;
	public static String start =null;
	public static String end;
	public static int times=1;
	public static int deviceId=-1;
	public static String file = "metric.txt";
	public static long pageSize=-1;
	public static String names;
	public static String url;
	public static void parserCmd(String[] args) {
		Options options = new Options();
		options.addOption("h", "help", false, "Print this usage information");
		options.addOption("f", "frequency", true, "how long create data once(unit:s) default is 60s");
	//	options.addOption("c", "config", true, "the config file default:metric.txt means:bin/conf/metric.txt");
		options.addOption("z", "zookeeper", true, "The connection info of zk,like:master.htdata.com:2181 default use the config htiiot.zookeeper in bin/conf/zookeeper.properties");
		options.addOption("t", "tenantids", true, "Which tenant you want create data");
		options.addOption("p", "pageSize", true, "How much device while you simulation");
	//	options.addOption("s", "start", true, "start Time");
	//	options.addOption("e", "end", true, "endTime");
	//	options.addOption("d", "deviceId", true, "deviceId");
	//	options.addOption("n", "names", true, "name");
		//options.addOption("tp", "topic", true, "topic");
	//	options.addOption("stp", "stattopic", true, "stattopic");
		options.addOption("u", "url", true, "rest url");
		CommandLine cmd=null;
		CommandLineParser parser = new BasicParser();
		try {
			cmd = parser.parse(options, args);
		} catch (org.apache.commons.cli.ParseException e1) {
			HelpFormatter formatter = new HelpFormatter();
			formatter.printHelp("create tsdb table", options);
			e1.printStackTrace();
			System.exit(0);
		}
		if(cmd.hasOption("h")){
			HelpFormatter formatter = new HelpFormatter();
			formatter.printHelp("OLDStore", options);
			System.exit(0);
		}
		
		if(cmd.hasOption("z")){
			zk = cmd.getOptionValue("z");
			System.setProperty("htiiot.zookeeper", zk);
		}
		
		if(cmd.hasOption("f")){
			times = Integer.parseInt(cmd.getOptionValue("f"));
		}
		if(cmd.hasOption("p")){
			pageSize = Long.parseLong(cmd.getOptionValue("p"));
		}
		if(cmd.hasOption("c")){
			file = cmd.getOptionValue("c");
		}
		if(cmd.hasOption("t")){
			tenantIds = cmd.getOptionValue("t");
		}
		if(cmd.hasOption("s")){
			start = cmd.getOptionValue("s");
		}
		if(cmd.hasOption("e")){
			end = cmd.getOptionValue("e");
		}
		if(cmd.hasOption("n")){
			names = cmd.getOptionValue("n");
		}
		if(cmd.hasOption("tp")){
			topic = cmd.getOptionValue("tp");
		}
		if(cmd.hasOption("stp")){
			stattopic = cmd.getOptionValue("stp");
		}
		
		if(cmd.hasOption("d")){
			deviceId = Integer.parseInt(cmd.getOptionValue("d"));
		}
		if(cmd.hasOption("u")){
			url = cmd.getOptionValue("u");
		}
		
		
	}

}
